package com.ylsk.statistics.controller;

import com.google.common.collect.Maps;
import com.ylsk.common.core.controller.BaseController;
import com.ylsk.common.core.domain.AjaxResult;
import com.ylsk.statistics.service.BigScreenService;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistics/bigScreen/")
public class BigScreenController extends BaseController {

    @Autowired
    private BigScreenService bigScreenService;

    /**
     * 大屏数量统计
     * @return
     */
    @GetMapping("selectNumberTotal")
    public AjaxResult selectNumberTotal()
    {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> selectNumberTotal = bigScreenService.selectNumberTotal();
        for (Map<String, Object> map : selectNumberTotal) {
            resultMap.put(String.valueOf(map.get("title")),Integer.valueOf(map.get("num").toString()));
        }
        return AjaxResult.success(resultMap);
    }

    /**
     * 大屏 今日检查于未检查数量统计
     * @return
     */
    @GetMapping("selectTodayCheckTotal")
    public AjaxResult selectTodayCheckTotal()
    {
        Map<String, Object> map = bigScreenService.selectTodayCheckTotal();
        return AjaxResult.success(map);
    }

    /**
     * 大屏 施工状态实时统计
     * @return
     */
    @GetMapping("selectConstructionStatusTotal")
    public AjaxResult selectConstructionStatusTotal()
    {
        List<Map<String, Object>> mapList = bigScreenService.selectConstructionStatusTotal();
        return AjaxResult.success(mapList);
    }

    public void buildConstructionStatusData(List<Map<String,Object>> list,Integer value,String name){
        Map<String,Object> map = Maps.newHashMap();
        map.put("value",value);
        map.put("name",name);
        list.add(map);
    }
    /**
     * 大屏 施工问题统计
     * @return
     */
    @GetMapping("selectConstructionProblemTotal")
    public AjaxResult selectConstructionProblemTotal()
    {
        List<Map<String,Object>> list = Lists.newArrayList();
        Map<String, Object> problemTotal = bigScreenService.selectConstructionProblemTotal();

        buildConstructionStatusData(list,problemTotal == null ? 0 : new Integer(String.valueOf(problemTotal.get("dzg"))),"待整改");
        buildConstructionStatusData(list,problemTotal == null ? 0 : new Integer(String.valueOf(problemTotal.get("wzg"))),"未整改");
        buildConstructionStatusData(list,problemTotal == null ? 0 : new Integer(String.valueOf(problemTotal.get("zgtg"))),"整改通过");
        return AjaxResult.success(list);
    }

    /**
     * 大屏 施工检查按月统计
     * @return
     */
    @GetMapping("selectCheckTotalByMonth")
    public AjaxResult selectCheckTotalByMonth()
    {
        Map<String, Integer> map = bigScreenService.selectCheckTotalByMonth();
        return AjaxResult.success(map);
        //Integer[] result = new Integer[]{20,0,22,45,34,54};
        //return AjaxResult.success(result);
    }
}
